﻿Imports EstoqueBLL
Imports VendasBLL
Public Class PermissaoUC
    Dim objBLL As New PermissaoBLL
    Dim objbll2 As New UsuarioBLL
#Region "Alterar"
    Private Sub TSBAlterar_Click(sender As System.Object, e As System.EventArgs) Handles TSBAlterar.Click
        Try
            Dim codigo As Integer
            For Each linha As DataGridViewRow In DGVDados.SelectedRows
                If (Not linha.Cells("usu_codigo") Is Nothing) Then
                    codigo = Val(linha.Cells("usu_codigo").Value)
                End If
            Next
            Dim cad As New PermissaoCAD
            If (codigo > 0) Then
                cad.lcodigo.Text = codigo
                cad.lcodigo.Visible = True
                cad.usuario = codigo
                TSBAlterar.BackColor = Color.Gainsboro
                cad.ShowDialog()
                CarregaGrid()
            Else
                MessageBox.Show("Selecione um usuário", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Erro:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Finally
            TSBAlterar.BackColor = Color.Transparent
        End Try
    End Sub
#End Region

#Region "Carrega grid"
    Sub CarregaGrid()
        DGVDados.DataSource = objbll2.buscar(Nothing, 9)
        DGVDados.Refresh()
    End Sub
#End Region

#Region "KeyDown Form"
    Private Sub IventarioUC_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If (e.KeyCode = Keys.Enter) Then
            SendKeys.Send("{TAB}")
        End If
        If (e.KeyCode = Keys.Escape) Then
            TSBVoltar_Click(Nothing, Nothing)
        End If
    End Sub
#End Region

#Region "Load"
    Private Sub CargosUC_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        CarregaGrid()
        
    End Sub
#End Region

#Region "Voltar"
    Private Sub TSBVoltar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TSBVoltar.Click
        statustabestoque = "N"
        Dispose()
    End Sub
#End Region

#Region "Cor de fundo do datagridview"
    Private Sub DGVDados_RowPrePaint(sender As System.Object, e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DGVDados.RowPrePaint
        If DGVDados.Rows(e.RowIndex).Index Mod (2) = 1 Then
            DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Gainsboro
        End If
    End Sub
#End Region

#Region "DatagridView Alterar com duplo click"
    Private Sub DGVDado_CellDoubleClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVDados.CellDoubleClick
        TSBAlterar_Click(Nothing, Nothing)
    End Sub
#End Region

#Region "DatagridView Alterar com enter"
    Private Sub DGVDado_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles DGVDados.KeyPress
        If e.KeyChar = Convert.ToChar(Keys.Return) Then
            TSBAlterar_Click(Nothing, Nothing)
        End If
    End Sub
#End Region

End Class
